{{#if (has-feature "Namespaces")}}
  <PageHeader as |p|>
    <p.levelLeft>
      <h1 class="title is-3">
        Namespaces
      </h1>
    </p.levelLeft>
  </PageHeader>

  <Toolbar>
    <ToolbarActions>
      <ToolbarLink
        @type="add"
        @params={{array 'vault.cluster.access.namespaces.create'}}
      >
        Create namespace
      </ToolbarLink>
    </ToolbarActions>
  </Toolbar>

  <ListView @items={{model}} @itemNoun="namespace" as |list|>
    {{#if list.empty}}
      <list.empty>
        {{#link-to "vault.cluster.access.namespaces.create"}}
          Create Namespace
        {{/link-to}}

        <LearnLink @path="/vault/security/namespaces">
          Learn more
        </LearnLink>
      </list.empty>
    {{else}}
      <ListItem as |Item|>
        <Item.content>
          {{list.item.id}}
        </Item.content>
        <Item.menu as |m|>
          {{#with (concat currentNamespace (if currentNamespace "/") list.item.id) as |targetNamespace|}}
            {{#if (contains targetNamespace accessibleNamespaces)}}
              <li class="action">
                {{#link-to "vault.cluster.secrets" (query-params namespace=targetNamespace) class="is-block"}}
                  Switch to Namespace
                {{/link-to}}
              </li>
            {{/if}}
          {{/with}}
          <li class="action">
            <m.Message
              @id={{list.item.id}}
              @confirmButtonText="Remove"
              @message="Any engines or mounts in this namespace will also be removed."
              @onConfirm={{action
                (perform
                  Item.callMethod
                  "destroyRecord"
                  list.item
                  (concat "Successfully deleted namespace: " list.item.id)
                  "There was an error deleting this namespace: "
                  (action "refreshNamespaceList")
                )
              }} />
          </li>
        </Item.menu>
      </ListItem>
    {{/if}}
  </ListView>
{{else}}
  <UpgradePage @title="Namespaces" @minimumEdition="Vault Enterprise Pro" />
{{/if}}
